package com.yq.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yq.entity.Communitye;
import com.yq.entity.Communitye;
import com.yq.service.CommunityeService;
import com.yq.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zxn
 * @since 2020-02-28
 */
@RestController
@RequestMapping("/communitye")
public class CommunityeController {
    @Autowired
    private CommunityeService communityeService;

    @RequestMapping("/listc")
    public R selectList(Integer current, Integer size, String username){
        if(current==null)current=0;
        if(size==null)size=10;
        if(username==null)username="";

        Page page=new Page(current,size);
        EntityWrapper<Communitye> shequEntityWrapper = new EntityWrapper<>();
        shequEntityWrapper.like("username", username);
        shequEntityWrapper.orderBy("id", true);
        Page<Communitye> equipmentCategoryPage = communityeService.selectPage(page, shequEntityWrapper);
        return R.ok().put("data",equipmentCategoryPage);
    }

    @RequestMapping("/list")
    public R selectlistc(Integer current, Integer size){
        if(current==null)current=0;
        if(size==null)size=10;

        Page<Communitye> equipmentCategoryPage = communityeService.selectPage(new Page<Communitye>(current, size));
        return R.ok().put("data",equipmentCategoryPage);
    }

    @RequestMapping("/insert")
    public R insertShequ(@RequestBody Communitye shequ){
        boolean insert = communityeService.insert(shequ);
        if(insert) return R.ok();
        return R.error();
    }


    @RequestMapping("/del")
    public R deleteShequ(@RequestBody Communitye shequ){
        EntityWrapper<Communitye> shequEntityWrapper = new EntityWrapper<>();
        shequEntityWrapper.eq("commnuityname", shequ.getCommnuityname());

        boolean insert = communityeService.delete(shequEntityWrapper);
        if(insert) return R.ok();
        return R.error();
    }

    @RequestMapping("/update")
    public R updateShequ(@RequestBody Communitye shequ){
        EntityWrapper<Communitye> shequEntityWrapper = new EntityWrapper<>();
        shequEntityWrapper.eq("id", shequ.getId());

        boolean insert = communityeService.update(shequ, shequEntityWrapper);
        if(insert) return R.ok();
        return R.error();
    }
}

